define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'meetingcontent/index' + location.search,
                    add_url: 'meetingcontent/add?meeting_id='+$('#meeting_id').val()+"&status="+$('#status').val(),
                    edit_url: 'meetingcontent/edit',
                    del_url: 'meetingcontent/del',
                    multi_url: 'meetingcontent/multi',
                    import_url: 'meetingcontent/import',
                    table: 'meeting_content',
                }
            });

            var table = $("#table");
            $status=$('#status').val();
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',

                onLoadSuccess:function (data){
                    //根据选项卡，展示对应字段
                    table.bootstrapTable('showColumn','project_id');
                    if($status == 0){
                        table.bootstrapTable('hideColumn','project_id');
                    }

                },
                onPostBody:function(){

                },

                searchFormVisible:false,
               
                search:false,
                 showExport: false,

                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        // {field: 'user_id', title: __('user_id'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id'),searchList: $.getJSON("meetingcontent/admin"),operate: 'FIND_IN_SET',formatter: function (value,row) {
                            return row.user_id_text;
                        }},
                        {field: 'project_id', title: __('project_id'),searchList: $.getJSON("meetingcontent/project"),operate: 'FIND_IN_SET',formatter: function (value,row) {
                            return row.project_id_text;
                        }},
                      
                        {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'buttons',width: "120px", operate: false,title: __('查看'),table: table,events: Table.api.events.operate,buttons: [
                            {
                                name: 'detail',
                                text: '查看详细',
                                title: '查看详细',
                                extend: 'data-area= \'["500px", "500px"]\'',
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'meetingcontent/detail'
                            },
                         
                        ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});